function data = createUncertainData(Y, C, uncertainty_type)


[N D] = size(Y);

data.Y = Y;
data.YYt = computeCrossProducts(Y);

if exist('C', 'var')
    data.uncertainty_type = uncertainty_type;
    
    % reformat uncertainty if necessary
    for n = 1:size(C, 3)
        switch uncertainty_type
            case 'full'
                
            case 'diagonal'
                C(:, :, n) = diag(diag(C(:, :, n)));
            case 'spherical'
                C(:, :, n) = eye(D)*mean(diag(C(:, :, n)));
            otherwise
                error(['Unknown covariance type ', uncertainty_type]);
        end
    end

    % precompute data
    if size(Y, 1) == size(C, 3)
        data.C = C;
        
        data.invC = zeros(D, D, N);
        data.logdetC = zeros(N, 1);
        data.invCy = zeros(N, D);
        data.yinvCy = zeros(N, 1);
        for n = 1:size(data.Y, 1)
            data.invC(:, :, n) = inv(data.C(:, :, n));
            data.logdetC(n, 1) = logdet_chol(data.C(:, :, n));

            data.invCy(n, :) = data.invC(:, :, n)*data.Y(n, :)';
            data.yinvCy(n, 1) = data.Y(n, :)*data.invC(:, :, n)*data.Y(n, :)';
        end
    else
        invC = inv(C);
        
        data.C = reshape(C(:)*ones(1, N), D, D, N);
        data.logdetC = logdet_chol(C)*ones(N, 1);
        data.invC = reshape(invC(:)*ones(1, N), D, D, N);

        data.invCy = data.Y*invC;
        data.yinvCy = reshape(data.YYt, D*D, N)'*reshape(inv(C), D*D, 1);
    end
end
